
package  main

import (
	"fmt"
)

//不定参数本质是slice
func hell(num ...int){
	num[0] = 18
	num[1] = 20
}

func test1() {
	a := []int{1,2,3}
	hell(a...)
	fmt.Println(a)
}

//slice
func test2()  {
	a := [5]int{1,2,3,4,5}
	t := a[2:5]

	fmt.Printf("---%+v, %v %v\n",t, cap(t), len(t))
}

//笔记数组，长度要一样
func test3()  {
	a := [2]int{1,2}
	b := [2]int{1,2}

	if a == b {
		fmt.Println("a==b")
	}
}

//12
func test4()  {
	var i interface{}
	if i == nil {
		fmt.Println("i is nil")
	}
	s := make(map[string]string)
	s["a"] = "good"
	delete(s, "hh")
	fmt.Println(s)
}

func deferTest1(num int){
	fmt.Printf("deferTest1 num:%v \n", num)
}

//13
func test5() error{
	i := -5
	j := 5
	fmt.Printf("___i=%+d, j=%+d \n", i, j)
	//在执行时会保留一份副本，此时i=-5
	defer deferTest1(i)
	i = i + 10
	var str string = "22"
	fmt.Println(str)

	//长度与容量
	s := [3]int{1,2,3}
	a := s[:0]
	b := s[:2]
	c := s[2:2:cap(s)]
	fmt.Printf("a len:%v cap:%v \n", len(a), cap(a))
	fmt.Println(cap(b), cap(c), c)

	m := make(map[string]int)        //A
	m["a"] = 1
	if v, ok:= m["a"]; ok==true {  //B
		fmt.Println(v)
	}

	return fmt.Errorf("err")
}



func main() {

	test1()
	test2()
	test3()
	test4()
	test5()
	type Person struct{age int }
	a := Person { 28}
	//1
	defer fmt.Println("1",a.age)
	//2
	defer func(* Person){
		fmt.Println("2",a.age)
	}(&a)

	//3
	defer func(){
		fmt.Println("3",a.age)
	}()
	a.age++

	s := Person{}
	p := &s
	g(s)
	g(p)
}

func g(x interface{}){
	fmt.Println(x)
	return
}

